package com.ss.android.article.base.feature.detail2.widget.tagview;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;

public class FlowLayout extends ViewGroup {
    public static final class LayoutParams extends ViewGroup.LayoutParams {
        static int a = -1;
        int b;
        int c;
        int d;
        int e;
        private boolean f;


        public LayoutParams(int arg2) {
            super(-2, arg2);
            this.d = LayoutParams.a;
            this.e = LayoutParams.a;
            this.f = false;
        }

        public LayoutParams(Context arg4, AttributeSet arg5) {
            super(arg4, arg5);
            this.d = LayoutParams.a;
            this.e = LayoutParams.a;
            this.f = false;
            TypedArray typedArray = arg4.obtainStyledAttributes(arg5, com.ss.android.e.b.FlowLayout_LayoutParams);
            try {
                this.d = typedArray.getDimensionPixelSize(com.ss.android.e.b.FlowLayout_LayoutParams_layout_horizontalSpacing, LayoutParams.a);
                this.e = typedArray.getDimensionPixelSize(com.ss.android.e.b.FlowLayout_LayoutParams_layout_verticalSpacing, LayoutParams.a);
                this.f = typedArray.getBoolean(com.ss.android.e.b.FlowLayout_LayoutParams_layout_newLine, false);
            } catch (Throwable v0) {
                typedArray.recycle();
                throw v0;
            }

            typedArray.recycle();
        }

        public LayoutParams(ViewGroup.LayoutParams arg2) {
            super(arg2);
            this.d = LayoutParams.a;
            this.e = LayoutParams.a;
            this.f = false;
        }

        static boolean a(LayoutParams arg1) {
            return arg1.f;
        }

        static int b(LayoutParams arg1) {
            return arg1.e;
        }

        static int c(LayoutParams arg1) {
            return arg1.d;
        }

        static int d(LayoutParams arg1) {
            return arg1.b;
        }

        static int e(LayoutParams arg1) {
            return arg1.c;
        }
    }

    private int a;
    private int b;
    private int c;
    private boolean d;

    public FlowLayout(Context arg2) {
        super(arg2);
        this.a = 0;
        this.b = 0;
        this.c = 0;
        this.d = false;
        this.a(arg2, null);
    }

    public FlowLayout(Context arg2, AttributeSet arg3) {
        super(arg2, arg3);
        this.a = 0;
        this.b = 0;
        this.c = 0;
        this.d = false;
        this.a(arg2, arg3);
    }

    public FlowLayout(Context arg2, AttributeSet arg3, int arg4) {
        super(arg2, arg3, arg4);
        this.a = 0;
        this.b = 0;
        this.c = 0;
        this.d = false;
        this.a(arg2, arg3);
    }

    private void a(Context arg4, AttributeSet arg5) {
        TypedArray v1 = arg4.obtainStyledAttributes(arg5, com.ss.android.e.b.FlowLayout);
        try {
            this.a = v1.getDimensionPixelSize(com.ss.android.e.b.FlowLayout_horizontalSpacing, 0);
            this.b = v1.getDimensionPixelSize(com.ss.android.e.b.FlowLayout_verticalSpacing, 0);
            this.c = v1.getInteger(com.ss.android.e.b.FlowLayout_flowOrientation, 0);
            this.d = v1.getBoolean(com.ss.android.e.b.FlowLayout_debugDraw, false);
        } catch (Throwable v0) {
            v1.recycle();
            throw v0;
        }

        v1.recycle();
    }

    private static Paint a(int arg2) {
        Paint v0 = new Paint();
        v0.setAntiAlias(true);
        v0.setColor(arg2);
        v0.setStrokeWidth(2f);
        return v0;
    }

    protected boolean checkLayoutParams(ViewGroup.LayoutParams arg2) {
        return arg2 instanceof LayoutParams;
    }

    protected boolean drawChild(Canvas arg20, View arg21, long arg22) {
        float v1;
        float v3;
        float v2;
        boolean v17 = super.drawChild(arg20, arg21, arg22);
        if (this.d) {
            Paint v6 = a(-256);
            Paint v15 = a(-16711936);
            Paint v18 = a(-65536);
            ViewGroup.LayoutParams v16 = arg21.getLayoutParams();
            if (LayoutParams.c(((LayoutParams) v16)) > 0) {
                v2 = ((float) arg21.getRight());
                v3 = (((float) arg21.getHeight())) / 2f + (((float) arg21.getTop()));
                arg20.drawLine(v2, v3, v2 + (((float) LayoutParams.c(((LayoutParams) v16)))), v3, v6);
                arg20.drawLine((((float) LayoutParams.c(((LayoutParams) v16)))) + v2 - 4f, v3 - 4f, v2 + (((float) LayoutParams.c(((LayoutParams) v16)))), v3, v6);
                arg20.drawLine((((float) LayoutParams.c(((LayoutParams) v16)))) + v2 - 4f, v3 + 4f, v2 + (((float) LayoutParams.c(((LayoutParams) v16)))), v3, v6);
            } else if (this.a > 0) {
                float v8 = ((float) arg21.getRight());
                float v9 = (((float) arg21.getTop())) + (((float) arg21.getHeight())) / 2f;
                arg20.drawLine(v8, v9, v8 + (((float) this.a)), v9, v15);
                arg20.drawLine((((float) this.a)) + v8 - 4f, v9 - 4f, v8 + (((float) this.a)), v9, v15);
                arg20.drawLine((((float) this.a)) + v8 - 4f, v9 + 4f, v8 + (((float) this.a)), v9, v15);
            }

            if (LayoutParams.b(((LayoutParams) v16)) > 0) {
                v2 = (((float) arg21.getWidth())) / 2f + (((float) arg21.getLeft()));
                v3 = ((float) arg21.getBottom());
                arg20.drawLine(v2, v3, v2, v3 + (((float) LayoutParams.b(((LayoutParams) v16)))), v6);
                arg20.drawLine(v2 - 4f, (((float) LayoutParams.b(((LayoutParams) v16)))) + v3 - 4f, v2, v3 + (((float) LayoutParams.b(((LayoutParams) v16)))), v6);
                arg20.drawLine(v2 + 4f, (((float) LayoutParams.b(((LayoutParams) v16)))) + v3 - 4f, v2, v3 + (((float) LayoutParams.b(((LayoutParams) v16)))), v6);
            } else if (this.b > 0) {
                float v11 = (((float) arg21.getLeft())) + (((float) arg21.getWidth())) / 2f;
                float v12 = ((float) arg21.getBottom());
                arg20.drawLine(v11, v12, v11, v12 + (((float) this.b)), v15);
                arg20.drawLine(v11 - 4f, (((float) this.b)) + v12 - 4f, v11, v12 + (((float) this.b)), v15);
                arg20.drawLine(v11 + 4f, (((float) this.b)) + v12 - 4f, v11, v12 + (((float) this.b)), v15);
            }

            if (!LayoutParams.a(((LayoutParams) v16))) {
                return v17;
            }

            if (this.c == 0) {
                v2 = ((float) arg21.getLeft());
                v1 = (((float) arg21.getTop())) + (((float) arg21.getHeight())) / 2f;
                arg20.drawLine(v2, v1 - 6f, v2, v1 + 6f, v18);
                return v17;
            }

            v1 = (((float) arg21.getLeft())) + (((float) arg21.getWidth())) / 2f;
            v3 = ((float) arg21.getTop());
            arg20.drawLine(v1 - 6f, v3, 6f + v1, v3, v18);
        }

        return v17;
    }

    protected ViewGroup.LayoutParams generateDefaultLayoutParams() {
        return new LayoutParams(-2);
    }

    public ViewGroup.LayoutParams generateLayoutParams(AttributeSet arg3) {
        return new LayoutParams(this.getContext(), arg3);
    }

    protected ViewGroup.LayoutParams generateLayoutParams(ViewGroup.LayoutParams arg2) {
        return new LayoutParams(arg2);
    }

    protected void onLayout(boolean arg9, int arg10, int arg11, int arg12, int arg13) {
        int v2 = this.getChildCount();
        int v1;
        for (v1 = 0; v1 < v2; ++v1) {
            View v3 = this.getChildAt(v1);
            ViewGroup.LayoutParams v0 = v3.getLayoutParams();
            v3.layout(LayoutParams.d(((LayoutParams) v0)), LayoutParams.e(((LayoutParams) v0)), LayoutParams.d(((LayoutParams) v0)) + v3.getMeasuredWidth(), LayoutParams.e(((LayoutParams) v0)) + v3.getMeasuredHeight());
        }
    }

    protected void onMeasure(int arg21, int arg22) {
        int v19;
        int v16;
        int v9;
        int v6;
        int v4 = View.MeasureSpec.getSize(arg21) - this.getPaddingRight() - this.getPaddingLeft();
        int v5 = View.MeasureSpec.getSize(arg22) - this.getPaddingTop() - this.getPaddingBottom();
        int v2 = View.MeasureSpec.getMode(arg21);
        int v3 = View.MeasureSpec.getMode(arg22);
        if (this.c == 0) {
            v3 = v2;
        } else {
            v4 = v5;
        }

        int v14 = 0;
        int v13 = 0;
        int v11 = 0;
        int v10 = 0;
        int v15 = 0;
        int v18 = this.getChildCount();
        int v17 = 0;
        for (v2 = 0; v17 < v18; v2 = v6) {
            View v8 = this.getChildAt(v17);
            if (v8.getVisibility() != GONE) {
                ViewGroup.LayoutParams v2_1 = v8.getLayoutParams();
                v8.measure(getChildMeasureSpec(arg21, this.getPaddingLeft() + this.getPaddingRight(), ((LayoutParams) v2_1).width), getChildMeasureSpec(arg22, this.getPaddingTop() + this.getPaddingBottom(), ((LayoutParams) v2_1).height));
                v5 = ((LayoutParams) v2_1).d != LayoutParams.a ? 1 : 0;
                v5 = v5 != 0 ? LayoutParams.c(((LayoutParams) v2_1)) : this.a;
                v6 = ((LayoutParams) v2_1).e != LayoutParams.a ? 1 : 0;
                v6 = v6 != 0 ? LayoutParams.b(((LayoutParams) v2_1)) : this.b;
                int v7 = v8.getMeasuredWidth();
                int v8_1 = v8.getMeasuredHeight();
                if (this.c == 0) {
                    v9 = v6;
                    v6 = v7;
                    v7 = v8_1;
                } else {
                    v9 = v5;
                    v5 = v6;
                    v6 = v8_1;
                }

                v11 += v6;
                int v12 = v11 + v5;
                if (!LayoutParams.a(((LayoutParams) v2_1))) {
                    if (v3 != 0 && v11 > v4) {
                        v16 = 1;
                    }else {
                        v16 = 0;
                    }
                } else {
                    v16 = 1;
                }

                if (v16 != 0) {
                    v12 = v7;
                    v13 = v7 + v9;
                    v11 = v5 + v6;
                    v5 = v10 + v14;
                    v10 = v6;
                } else {
                    v5 = v10;
                    v10 = v11;
                    v11 = v12;
                    v12 = v13;
                    v13 = v14;
                }

                v14 = Math.max(v13, v9 + v7);
                v13 = Math.max(v12, v7);
                if (this.c == 0) {
                    v6 = this.getPaddingLeft() + v10 - v6;
                    v7 = this.getPaddingTop() + v5;
                } else {
                    v6 = this.getPaddingLeft() + v5;
                    v7 = this.getPaddingTop() + v10 - v8_1;
                }

                ((LayoutParams) v2_1).b = v6;
                ((LayoutParams) v2_1).c = v7;
                v2 = Math.max(v15, v10);
                v6 = v5 + v13;
            } else {
                v5 = v10;
                v6 = v2;
                v2 = v15;
            }

            ++v17;
            v15 = v2;
            v10 = v5;
        }

        if (this.c == 0) {
            v19 = this.getPaddingLeft() + this.getPaddingRight() + v15;
            v3 = v2 + (this.getPaddingBottom() + this.getPaddingTop());
            v2 = v19;
        } else {
            v19 = this.getPaddingBottom() + this.getPaddingTop() + v15;
            v3 = v2 + (this.getPaddingLeft() + this.getPaddingRight());
            v2 = v19;
        }

        if (this.c == 0) {
            this.setMeasuredDimension(resolveSize(v2, arg21), resolveSize(v3, arg22));
        } else {
            this.setMeasuredDimension(resolveSize(v3, arg21), resolveSize(v2, arg22));
        }
    }

    public void setHorizontalSpacing(int arg1) {
        this.a = arg1;
    }

    public void setVerticalSpacing(int arg1) {
        this.b = arg1;
    }
}

